package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ClassificationlistBean;
import com.example.myapplication.government.DemandsActivity;
import com.google.gson.Gson;

import java.util.List;
import java.util.logging.Handler;

public class ClassificationApter extends  RecyclerView.Adapter<ClassificationApter.Myhot>{
    private Context context ;
    private View view;
    private List<ClassificationlistBean.RowsBean> list;

    public ClassificationApter(Context context, List<ClassificationlistBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_sever,null);
        return new ClassificationApter.Myhot(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Myhot holder, int position) {
        Glide.with(context).load("http://124.93.196.45:10001"+list.get(position).getImgUrl()).into(holder.sever_tv_img);
        holder.sever_iv_text.setText(list.get(position).getName());
        holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context,DemandsActivity.class );
                    intent.putExtra("DemandsActivityID",String.valueOf(list.get(position).getId()));
                    context.startActivity(intent);
                }
            });

    }

    @Override
    public int getItemCount() {
       // return classificationlistBean.getRows().size();
        return 8;
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView sever_iv_text;
        private final ImageView sever_tv_img;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            sever_tv_img = itemView.findViewById(R.id.sever_tv_img);
            sever_iv_text = itemView.findViewById(R.id.sever_iv_text);
        }
    }
}
